package com.ran.controller;

import com.alibaba.fastjson.JSON;
import com.ran.entity.book;
import com.ran.service.bookService;
import com.ran.service.serviceImpl.bookServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 *bookQueryController
 */
public class BookQueryServlet extends HttpServlet {
    private bookService bookserviceimpl = new bookServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        req.setCharacterEncoding("UTF-8");
        resp.setContentType("text/html;charset=UTF-8");
//        接收前端请求的数据
        String text = req.getParameter("text");
//        业务交付
        List<book> book = this.bookserviceimpl.getbooks(text);
        req.getSession().setAttribute("book", book);
        if(book.size()!=0){
            req.getRequestDispatcher("/javaweb/displayBook.jsp").forward(req,resp);
        }else{
            req.getRequestDispatcher("/javaweb/error.jsp").forward(req,resp);
        }

    }
}
